package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.FindPackersSearchEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
*@author liwei
*@date 2020/10/13
*description:
*/
public class FindPackerSearchAdapter extends BaseRecycleAdapter<FindPackersSearchEntity> {

    private RequestManager requestManager;
    public FindPackerSearchAdapter(Context context, List<FindPackersSearchEntity> data, RequestManager requestManager) {
        super(context, R.layout.item_find_packers_search, data);
        this.requestManager = requestManager;
    }

    @Override
    public void convert(ItemViewHolder holder, FindPackersSearchEntity listPackersBean) {
        holder.setBinding(BR.viewModel, listPackersBean);
        ImageView ivPackerAvatar = holder.itemView.findViewById(R.id.iv_packer_avatar);
        TextView tvTime = holder.itemView.findViewById(R.id.tv_time);
        if (null != listPackersBean.getAvatarAddress() && !TextUtils.isEmpty(listPackersBean.getAvatarAddress())) {
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.packer_avatar)
                    .transforms(new CenterCrop(), new RoundedCorners(8));
            requestManager.load(listPackersBean.getAvatarAddress()).apply(options).into(ivPackerAvatar);
        } else {
            requestManager.load(R.mipmap.packer_avatar).into(ivPackerAvatar);
        }
        tvTime.setText(String.format("%s 发布", DateUtils.timestampToDate(listPackersBean.getCreateTime())));
        TextView name1 = holder.itemView.findViewById(R.id.tv_packers_title);
        name1.setText(listPackersBean.getTeamName());
    }
}
